<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2018/12/3
 * Time: 13:51
 */

namespace app\storage\model;


use think\Model;

class SeatModel extends Model
{
    protected $table = 'iwh_seat';
    protected $pk = 'uuid';


    public function Storage()
    {
        return $this->belongsTo('StorageModel', 'storage_uuid', 'uuid')->bind('name');
    }

    public function getSeat($condition){
        $where = $condition['where'];
        $pageIndex = $condition['pageIndex'];
        $pageSize = $condition['pageSize'];
        $ret['total'] = $this->alias('a')
            ->join(['iwh_storage'=>'b'],'a.storage_uuid = b.uuid')
            ->where($where)
            ->count();

        $ret['row'] = $this->alias('a')->field('a.*,b.name')
            ->join(['iwh_storage'=>'b'],'a.storage_uuid = b.uuid')
            ->order('storage_uuid asc,seat_code asc')
            ->page($pageIndex, $pageSize)
            ->where($where)
            ->select();
        return $ret;
    }

    public function querySeat($condition){
        $where = $condition['where'];
        $pageIndex = $condition['pageIndex'];
        $pageSize = $condition['pageSize'];
        $ret['total'] = $this->alias('a')
            ->join(['iwh_storage'=>'b'],'a.storage_uuid = b.uuid')
            ->where($where)
            ->count();

        $ret['row'] = $this->alias('a')
            ->join(['iwh_storage'=>'b'],'a.storage_uuid = b.uuid')
            ->order('storage_uuid asc,seat_code asc')
            ->page($pageIndex, $pageSize)
            ->where($where)
            ->select();

        return $ret;
    }
}